package com.yanyu.space.sys.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yanyu.space.common.core.bean.db.PageEntity;
import com.yanyu.space.common.db.pagination.PageUtil;
import com.yanyu.space.sys.bean.po.Post;
import com.yanyu.space.sys.bean.vo.post.PostSearchVo;
import com.yanyu.space.sys.dao.PostMapper;
import com.yanyu.space.sys.service.IPostService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 职位 业务实现类
 *
 * @author yanyu
 */
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IPostService {

    @Override
    public PageEntity<Post> listPage(PostSearchVo vo) {
        IPage<Post> page = baseMapper.selectPage(PageUtil.getParam(), Wrappers.<Post>lambdaQuery()
                .like(StringUtils.isNoneBlank(vo.getCode()), Post::getCode, vo.getCode())
                .like(StringUtils.isNoneBlank(vo.getName()), Post::getName, vo.getName())
                .eq(vo.getEnabled() != null, Post::getEnabled, vo.getEnabled())
                .orderByAsc(Post::getSort).orderByDesc(Post::getUpdateTime));
        return PageUtil.getResult(page);
    }
}
